package com.commods.main.view.components.historicalChart.proto.temp
{
	import flash.events.MouseEvent;
	import flash.utils.Dictionary;
	
	import mx.core.Container;
	import mx.core.IVisualElement;
	import mx.core.UIComponent;
	import mx.effects.Effect;
	import mx.effects.Resize;
	
	import spark.components.Button;
	import spark.components.Group;

	/*static*/public class TempUtils
	{
		public function TempUtils()
		{
		}
		
		public static function rndRangeInt(min:Number, max:Number):int
		{
			return Math.floor(Math.random() * (max - min)) + min;
		}
		
		public static function dateAdd(datepart:String = "milliseconds", number:Number = 0, date:Date = null):Date {
			if (date == null) {
				/* Default to current date. */
				date = new Date();
			}
			
			var returnDate:Date = new Date(date.time);;
			
			switch (datepart.toLowerCase()) {
				case "fullyear":
				case "month":
				case "date":
				case "hours":
				case "minutes":
				case "seconds":
				case "milliseconds":
					returnDate[datepart] += number;
					break;
				default:
					/* Unknown date part, do nothing. */
					break;
			}
			return returnDate;
		}
		
		private var _originalWidth:Number;
		[Bindable]public var maximized:Boolean;
		public function toggleSize(target:UIComponent, restore:Boolean=false):void{
			var group:Group = target.parent as Group;
			var restore:Boolean = (target.percentWidth==100);
			for(var i:uint=0; i<group.numElements; i++){
				var curEl:UIComponent = group.getElementAt(i) as UIComponent;
				var show:Boolean = (restore || target==curEl);
				curEl.includeInLayout = curEl.visible = show;
				curEl.setStyle("resizeEffect", null);
			}

			if(restore){
				target.percentWidth = _originalWidth;
			}else{
				_originalWidth = target.percentWidth;
				target.percentWidth=100;
			}
			target.setStyle("resizeEffect", new Resize());
			
			maximized=!restore;
		}
		
		
		public function applyResizingEffect(group:Group, childType:Class=null):void{
			for(var i:uint=0; i<group.numElements; i++){
				var curEl:UIComponent = group.getElementAt(i) as UIComponent;
				if(childType && !(curEl is childType))continue;
				curEl.doubleClickEnabled = true;
				curEl.addEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClickResize);
			}
		}
		
		protected function onDoubleClickResize(event:MouseEvent):void{
			var _curTarget:UIComponent = event.currentTarget as UIComponent;
			toggleSize(_curTarget);
		
		}
	}
}